$(function() {
	FastClick.attach(document.body);
});

var statisticsSummary = new Vue({
	el: "body",
	data: {
		userid: "",
		nowYear: "",
		nowWeek: "",
		weekRange: "",
		fileData: "", //档案管理数量统计
		fileSearchTotal: "", //档案查询量统计
		lineTotal: "", //地下管线统计
		lineZongBiaoSum: "", //市政管线
		lineGuanXianSum: "", //长输工业管线
		projectTotal: "", //工程档案
		mapTotal: "", //测绘业务统计
		bookTotal: "", //馆内文书统计
		jiyaTotal: "", //积压档案统计
		guanxianTotal: "", //管线单位走访
		qitaTotal: ""
	},
	created: function() {
		_this = this; //防止出现闭包
		_this.userid = getUrlItem("userid"); //用户id
		//首先确定和数据总表一样的数据筛选周期
		var time = new Date();
		var year = time.getFullYear(); //当前实际年月日
		var month = time.getMonth() + 1;
		var day = time.getDate();
		_this.nowYear = time.getFullYear();

		var nowWeek = getWeekNumber(year, month, day); //当前实际周数
		var weekRange = getFirstAndLastDay(time); //得到当前周的起始
		var fridayString = getFirstAndLastDay(time, "line").friday.replace(/-/g, "/");
		var nowFridayObj = new Date(fridayString); //当前周五的时间对象
		var nowFridayYear = nowFridayObj.getFullYear(); //当前周五的年月日
		var nowFridayMonth = nowFridayObj.getMonth() + 1;
		var nowFridayDay = nowFridayObj.getDate();

		_this.nowWeek = getWeekNumber(nowFridayYear, nowFridayMonth, nowFridayDay);
		_this.weekRange = getFirstAndLastDay(nowFridayObj) //当前周五在第几周就显示该周是第几周

		var nowFridayLimit = fridayString + " 17:00:00" //得到本周五的17：00时间对象   
		var nowFridayLimitObj = new Date(nowFridayLimit)

		if(time < nowFridayLimitObj) { //现在的日子如果没到周五17：00         显示的是上周的数据   
			var nowFridayTime = nowFridayObj.getTime();
			var oneDayLong = 24 * 60 * 60 * 1000;
			var realTime = nowFridayTime - 7 * oneDayLong
			var real = new Date(realTime)
			var realyear = real.getFullYear();
			var realmonth = real.getMonth() + 1;
			var realday = real.getDate();
			_this.nowWeek = getWeekNumber(realyear, realmonth, realday);
			_this.weekRange = getFirstAndLastDay(real)
		}

		searchFileTreeTotal(_this)
		searchSearchFileTotal(_this)
		searchLineTotal(_this)
		searchProjectTotal(_this)
		searchMapProductTotal(_this)
		searchBookTotal(_this)
		searchJiyaTotal(_this)
		searchGuanXianTotal(_this)
		searchQiTaTotal(_this)

		_this.$nextTick(function() {
			setTimeout(function() {
				$(".statistics-summary-body").removeClass("hidden")
				$(".loader").addClass("hidden")
			}, 300)
		})
	},
	methods: {
		enterTotal: function() {
			location.href = "../statistics/statisticsTotalNew.html?userid=" + _this.userid
		},
		back: function() {
			window.history.go(-1); //返回上一页
		}
	}
})

//从url中截取传递到数据
function getUrlItem(name) { //id
	var url = location.search
	start = url.indexOf(name + "=")
	if(start != -1) {
		start = start + name.length + 1
		end = url.indexOf("&", start)
		if(end == -1) {
			end = url.length
			return unescape(url.substring(start, end))
		}
		return unescape(url.substring(start, end))
	}
	return '';
}

function searchFileTreeTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099//BhGgjAPI/DataSum.asmx/getArcTotalSum?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			a.fileData = jsondata
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});

}

function searchSearchFileTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/DataSum.asmx/getArcSum?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			a.fileSearchTotal = jsondata;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

function searchLineTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/DataSum.asmx/getLineSum?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			a.lineTotal = jsondata
			a.lineZongBiaoSum = jsondata["总表"]
			a.lineGuanXianSum = jsondata["工业管线"]
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});

}

function searchProjectTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/DataSum.asmx/getProjectArcSum?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			a.projectTotal = jsondata;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

function searchMapProductTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/DataSum.asmx/getGraphProductSum?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			a.mapTotal = jsondata;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});

}

function searchBookTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/DataSum.asmx/getBookSum?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			console.log(jsondata)
			a.bookTotal = jsondata
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

function searchJiyaTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/TempStatic.asmx/getTONGJI_TGCJY_Static?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			console.log(jsondata)
			_this.jiyaTotal = jsondata
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

function searchGuanXianTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/TempStatic.asmx/getTONGJI_TDWZF_Static?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			a.guanxianTotal = jsondata
			console.log(a.guanxianTotal)
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

function searchQiTaTotal(a) {
	$.ajax({
		type: "post",
		url: "http://47.92.116.158:8099/BhGgjAPI/TempStatic.asmx/getTONGJI_TDAN_Static2?callback=?",
		data: {
			"year": a.nowYear,
			"week": a.nowWeek,
			"year2": a.nowYear,
			"week2": a.nowWeek
		},
		dataType: "json",
		success: function(jsondata) {
			a.qitaTotal = jsondata[0]
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}